package com.bto.solar.work.controller;

import com.alibaba.fastjson2.JSONArray;
import com.bto.solar.work.common.R;
import com.bto.solar.work.constant.BizStageEnum;
import com.bto.solar.work.constant.BizTaskEnum;
import com.bto.solar.work.constant.BizTaskStateEnum;
import com.bto.solar.work.constant.Constants;
import com.bto.solar.work.dto.order.OrderStatesRes;
import com.bto.solar.work.service.BtoOrderStateService;
import com.bto.solar.work.vo.TaskCountVo;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 订单状态表：	订单状态包含多种情况情况	1、当前订单所处于的一个阶段（有些阶段是并行的，有些是依赖），一个订单同时存在多个阶段。阶段是业务上的划分，如何开启，业务代码控制。	2、各个阶段里面的一些状态（客户-待录入、客户-待签约、待踏勘、待设计、踏勘-初审通过、踏勘-总部审批、踏勘-终审 、工程-待分配、来料带录入 等等）。	    	状态数据本质上是对订单的标记，分类查询使用。阶段和状态并不具备耦合关系，只是标记查询的维度不同而已。	业务上允许查询 阶段是A  但是状态是 B阶段的=不存在此类数据		阶段+状态=联合索引=一个订单不存在一个阶段有相同的状态 前端控制器
 * </p>
 *
 * @author adrian
 * @since 2023-08-09
 */
@RestController
@RequestMapping("order-state")
public class OrderStateController {
    @Autowired
    private BtoOrderStateService btoOrderStateService;

    @ApiModelProperty("查询阶段任务状态字典")
    @GetMapping("dic")
    public R getStageTaskStateDic(){
        return R.ok(btoOrderStateService.getStageTaskStateDic());
    }


    @ApiModelProperty("查询订单状态信息")
    @GetMapping("")
    public R<OrderStatesRes> getOrderStatesInfo(@RequestParam String orderId){
        OrderStatesRes orderStatesRes = new OrderStatesRes();
        orderStatesRes.setOrderId(orderId);
        orderStatesRes.setCurrentOrderState(btoOrderStateService.getOrderCurrentStates(orderId));
        orderStatesRes.setOrderStates(btoOrderStateService.getOrderStates(orderId));
        return R.ok(orderStatesRes);
    }


    @ApiModelProperty("查询阶段信息")
    @GetMapping("stage")
    public R getStage(){
        return R.ok(btoOrderStateService.getStageTaskCount(null  ));
    }

    @ApiModelProperty("查询阶段任务信息")
    @GetMapping("stage-task")
    public R getStageTask(@RequestParam String stageId){
        return R.ok(btoOrderStateService.getStageTaskCount(stageId  ));
    }

    @ApiModelProperty("查询阶段任务状态信息")
    @GetMapping("stage-task-state")
    public R getStageTask(@RequestParam(required = false) String stageId , @RequestParam(required = false) String taskId ,
                          @RequestParam(required = false) String stateId){
        return R.ok(btoOrderStateService.getTaskStateCount(stageId , taskId  , stateId));
    }

    @ApiModelProperty("查询任务拒绝数量")
    @GetMapping("reject-count")
    public R getRejectCount(@RequestParam String stateId){
        return R.ok(btoOrderStateService.getTaskStateCount( null , null ,stateId));
    }

    @ApiModelProperty("查询设计阶段任务状态信息")
    @GetMapping("stage-design-state")
    public R getStageDesignTask(){
        return R.ok(btoOrderStateService.getStageDesignTask());
    }



}
